﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Text;
using System.Net;

namespace CSMF
{
    public partial class j02 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
            }
        }


        ///<summary>
        ///发送邮件
        ///</summary>
        public void SendMail(string title, StringBuilder sb)
        {
            string mailfrom = "join@csmff.com";
            SmtpClient smtp = new SmtpClient();
            //smtp.UseDefaultCredentials = true;
            //smtp.Credentials = new NetworkCredential("join@csmff.com", "j2o0i1n2");
            MailMessage message = new MailMessage(mailfrom, mailfrom);
            message.IsBodyHtml = true;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.Subject = title;
            message.Body = sb.ToString();
            smtp.Send(message);
            message.Dispose();
        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            if (CheckBox1.Checked == true)
            {
                if (txtJianjie.Text.Trim() != "")
                {
                    if (txtLianxiren.Value != null)
                    {
                        if (txtLianxifangshi.Value != null)
                        {
                            string title = "通向好莱坞参赛报名";
                            StringBuilder sb = new StringBuilder();
                            sb.Append("详细内容如下：<br><br>");
                            sb.Append("团队名称：" + Convert.ToString(txtTeamtitle.Value) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;导演:" + Convert.ToString(txtDaoyan.Value) + "<br><br>");
                            sb.Append("编辑：" + Convert.ToString(txtBianji.Value) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;摄影:" + Convert.ToString(txtSheying.Value) + "<br><br>");
                            sb.Append("后期：" + Convert.ToString(txtHouqi.Value) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其它:" + Convert.ToString(txtQita.Value) + "<br><br>");
                            sb.Append("团队／导演简介：" + txtJianjie.Text + "<br><br>");
                            sb.Append("---------------------------------------------------------------------- <br><br>");
                            sb.Append("作品参考链接：" + Convert.ToString(txtLink.Value) + "<br><br>");
                            sb.Append("联络人：" + Convert.ToString(txtLianxiren.Value) + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;联络人联系方式:" + Convert.ToString(txtLianxifangshi.Value) + "<br><br>");
                            sb.Append("联络人联系地址：" + Convert.ToString(txtLianxidizhi.Value) + "<br><br><br><br>");
                            sb.Append("---------------------------------------------------------------------- <br><br>");
                            sb.Append("(这是一封自动产生的email，请勿回复。) <br><br>");
                            sb.Append("---------------------------------------------------------------------- <br><br>");
                            SendMail(title, sb);

                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('报名参赛成功。');", true);
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('请填写联络人联系方式。');", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('请填写联络人。');", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('请填写团队／导演简介。');", true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aaa", "alert('请先阅读“海峡两岸微电影大赛-通向好莱坞之旅-参赛细则”。');", true);
            }
        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            txtTeamtitle.Value = null;
            txtDaoyan.Value = null;
            txtBianji.Value = null;
            txtSheying.Value = null;
            txtHouqi.Value = null;
            txtQita.Value = null;
            txtJianjie.Text = "";
            txtLink.Value = null;
            txtLianxiren.Value = null;
            txtLianxifangshi.Value = null;
            txtLianxidizhi.Value = null;
        }
    }
}
